package com.etc.library.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class EmailUtil {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    public void send(String subject,String text ,String to){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSentDate(new Date());
        message.setSubject(subject);
        message.setText(text);
        javaMailSender.send(message);
    }
    public void send(String subject,String text ,String to,String cc){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setCc(cc);
        message.setSentDate(new Date());
        message.setSubject(subject);
        message.setText(text);
        javaMailSender.send(message);
    }
    public void send(String subject,String text ,String... to){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSentDate(new Date());
        message.setSubject(subject);
        message.setText(text);
        javaMailSender.send(message);
    }
    public void send(String subject,String text ,String[] to,String[] cc){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setCc(cc);
        message.setSentDate(new Date());
        message.setSubject(subject);
        message.setText(text);
        javaMailSender.send(message);
    }
}
